home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / windows / java / demo / imagemap / clickarea.java < prev    next >
Encoding:
Java Source  |  1996-04-26  |  3.5 KB  |  103 lines

  1. /*
  2.  * @(#)ClickArea.java    1.5 96/04/24  
  3.  *
  4.  * Copyright (c) 1994-1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
  8.  * without fee is hereby granted. 
  9.  * Please refer to the file http://java.sun.com/copy_trademarks.html
  10.  * for further important copyright and trademark information and to
  11.  * http://java.sun.com/licensing.html for further important licensing
  12.  * information for the Java (tm) Technology.
  13.  * 
  14.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  15.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  18.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  19.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  20.  * 
  21.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  22.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  23.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  24.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  25.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  26.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  27.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
  28.  * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
  29.  * HIGH RISK ACTIVITIES.
  30.  */
  31.  
  32. import java.awt.Graphics;
  33.  
  34. /**
  35.  * An click feedback ImageArea class.
  36.  * This class extends the basic ImageArea Class to show the locations
  37.  * of clicks in the image in the status message area.  This utility
  38.  * ImageArea class is useful when setting up ImageMaps.
  39.  *
  40.  * @author     Jim Graham
  41.  * @version     1.5, 04/24/96
  42.  */
  43. class ClickArea extends ImageMapArea {
  44.     /** The X location of the last mouse press. */
  45.     int startx;
  46.     /** The Y location of the last mouse press. */
  47.     int starty;
  48.     /** A boolean to indicate whether we are currently being dragged. */
  49.     boolean dragging;
  50.  
  51.     static String ptstr(int x, int y) {
  52.     return "("+x+", "+y+")";
  53.     }
  54.  
  55.     /**
  56.      * When the user presses the mouse button, start showing coordinate
  57.      * feedback in the status message line.
  58.      */
  59.     public boolean press(int x, int y) {
  60.     showStatus("Clicked at "+ptstr(x, y));
  61.     startx = x;
  62.     starty = y;
  63.     dragging = true;
  64.     return false;
  65.     }
  66.  
  67.     /**
  68.      * Update the coordinate feedback every time the user moves the mouse
  69.      * while he has the button pressed.
  70.      */
  71.     public boolean drag(int x, int y) {
  72.     showStatus("Rectangle from "+ptstr(startx, starty)
  73.            +" to "+ptstr(x, y)
  74.            +" is "+(x-startx)+"x"+(y-starty));
  75.     return false;
  76.     }
  77.  
  78.     /**
  79.      * Update the coordinate feedback one last time when the user releases
  80.      * the mouse button.
  81.      */
  82.     public boolean lift(int x, int y) {
  83.     dragging = false;
  84.     return drag(x, y);
  85.     }
  86.  
  87.     /**
  88.      * This utility method returns the status string this area wants to
  89.      * put into the status bar.  If this area is currently animating
  90.      * a message, then that message takes precedence over any other area
  91.      * that a higher stacked area may want to display, otherwise the
  92.      * message from the higher stacked area takes precedence.
  93.      */
  94.     public String getStatus(String prevmsg) {
  95.     if (dragging) {
  96.         return (status != null) ? status : prevmsg;
  97.     } else {
  98.         return (prevmsg == null) ? status : prevmsg;
  99.     }
  100.     }
  101. }
  102.  
  103.